package com.powernode.business.service.impl;

import com.powernode.framework.config.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.powernode.business.domain.Attachment;
import com.powernode.business.mapper.AttachmentMapper;
import com.powernode.business.service.AttachmentService;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AttachmentServiceImpl implements AttachmentService{

    @Resource
    private AttachmentMapper attachmentMapper;

    @Autowired
    private ServerConfig serverConfig;

    @Override
    public int deleteByPrimaryKey(Integer fileId) {
        return attachmentMapper.deleteByPrimaryKey(fileId);
    }

    @Override
    public int insert(Attachment record) {
        return attachmentMapper.insert(record);
    }

    @Override
    public int insertSelective(Attachment record) {
        return attachmentMapper.insertSelective(record);
    }

    @Override
    public Attachment selectByPrimaryKey(Integer fileId) {
        return attachmentMapper.selectByPrimaryKey(fileId);
    }

    @Override
    public int updateByPrimaryKeySelective(Attachment record) {
        return attachmentMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Attachment record) {
        return attachmentMapper.updateByPrimaryKey(record);
    }

    /**
     * 获取当前车辆的大图
     * @param carNumber
     * @return
     */
    @Override
    public List<String> showCarImgs(String carNumber) {
        List<String> filePaths = attachmentMapper.selectCarImgs(carNumber);
        //拼接图片路径
        String url = serverConfig.getUrl();
        //url是项目路径 不能写死 从环境中取
        List<String> carImgs = filePaths.stream().map(img -> url + img).collect(Collectors.toList());
        return carImgs;
    }
}
